<meta title="广告列表" args="advSpaceId" width="800"/>
<div class="p">
    <div class="m-b-xs clearfix">
        <a href="javascript:;" class="btn btn-primary btn-xs btn-outline"
           s-click="add()">
            <i class="fa fa-plus"></i> 添加
        </a>
    </div>
    <div id="advsGrid"
         s='datac,nda,check'
         s-data="S.get('/api/adv-space-item/list/{advSpaceId}')">
        <table class="table table-striped table-bordered table-hover table-middle">
            <tr>
                <th>图片</th>
                <th>名称</th>
                <th>创建时间</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop">
            <tr s-loop-role="empty">
                <td colspan="7">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s-check-role="i" s="datac" class="adv">
                <td s="tpl">
                    <a href="{%=this.adv.picUrl%}" external target="_blank">
                        <img src="{%=this.adv.picUrl%}" style="max-width: 100px; max-height: 100px;"/>
                    </a>
                </td>
                <td name="adv.name"></td>
                <td name="adv.createTime"></td>
                <td name="adv.startTime"></td>
                <td name="adv.endTime"></td>
                <td s="tpl">
                    {%if(this.adv.valid){%}
                    <label class="label label-success">正常</label>
                    {%}else{%}
                    <label class="label label-default">锁定</label>
                    {%}%}
                </td>
                <td class="text-right">
                    <input autocomplete="off" type="button" class="btn btn-danger btn-outline btn-xs"
                           s-click="del(this)" value="移除"/>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">

    function add() {
        S.popupOpen("/adv/adv-selector.html").done(function (rs) {
            if (rs) {
                S.post("/api/adv-space-item/" + advSpaceId, {advIdList: rs.map(function(r) {
                        return r.id
                    })}).done(function(rs) {
                    $advsGrid.refresh()
                })
            }
        })
    }

    function del($this) {
        S.remove("/api/adv-space-item/" + $this.parent().data().id).done(function() {
            $advsGrid.refresh()
        })
    }

</script>